package com.bwie.parkdemo.widget.dialog;

import android.app.AlertDialog;
import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.bwie.parkdemo.R;

/**
 * 添加巡更地点dialog
 * */
public class AddPointDialog extends AlertDialog implements View.OnClickListener{

    private EditText edt;
    private Button cannel;
    private Button ok;
    private AddPointDialogCallBack callBack;

    public AddPointDialog(Context context) {
        super(context);
    }

    public AddPointDialog setCallBack(AddPointDialogCallBack callBack) {
        this.callBack = callBack;
        return this;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_addpoint);
        init();
    }

    private void init(){
        edt = findViewById(R.id.addpoint_dialog_edt);
        cannel = findViewById(R.id.addpoint_dialog_cannel);
        ok = findViewById(R.id.addpoint_dialog_ok);
        cannel.setOnClickListener(this);
        ok.setOnClickListener(this);
        edt.setText("后门");
    }

    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.addpoint_dialog_cannel){
            dismiss();
        }else {
            if (TextUtils.isEmpty(edt.getText())){
                Toast.makeText(getContext(),"输入内容为空",Toast.LENGTH_SHORT).show();
                return;
            }
            if (callBack == null){
                Toast.makeText(getContext(),"callback为空",Toast.LENGTH_SHORT).show();
                return;
            }
            callBack.addPointName(edt.getText().toString());
            dismiss();
        }
    }

    public interface AddPointDialogCallBack{
        void addPointName(String name);
    }

}
